package cc.lj.internal.coupons.domain.ticket.service.impl.useTicketRule;

import cc.lj.internal.api.ordershare.dto.OrderOnlineAPIDTO;
import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.coupons.domain.ticket.model.vo.TicketBatchDO;
import cc.lj.internal.coupons.domain.ticket.model.vo.TicketMainDO;
import cc.lj.internal.coupons.domain.ticket.service.AbstractUseTicketRuleDomainService;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.interfaces.dto.command.UseTicketCheckCommand;
import lj.internal.dict.enums.ticketBatch.EnumTicketStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 用券验证规则 - 券状态
 * @author liangxifeng
 * @date 2023/6/16 15:12
 */
@Service("useTicketStatusRuleDomainServiceImpl")
@Slf4j
public class UseTicketStatusRuleDomainServiceImpl extends AbstractUseTicketRuleDomainService {
    @Override
    protected void rule(TicketBatchDO batchDO, TicketMainDO ticketMainDO, UseTicketCheckCommand ticketCheckCommand, OrderOnlineAPIDTO orderOnlineAPIDTO) {
        log.info("【电子券用券验证】：券状态规则验证开始===");
        //电子券已使用
        if(ticketMainDO.getTicketStatus() == EnumTicketStatus.USED.getCode())
        {
            throw new ServiceException(CoupousExceptionEnum.TICKET_USED);
        }
        //电子券已作废
        if (ticketMainDO.getTicketStatus() ==  EnumTicketStatus.CANCEL.getCode())
        {
            throw new ServiceException(CoupousExceptionEnum.TICKET_CANCEL);
        }
        //电子券已过期
        if( ticketMainDO.getTicketStatus() == EnumTicketStatus.EXPIRED.getCode())
        {
            throw new ServiceException(CoupousExceptionEnum.TICKET_EXPIRE);
        }
        log.info("【电子券用券验证】：券状态规则验证通过===");
    }
}
